package com.xhsj.user.pms.patent.service.impl;

import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.xhsj.user.pms.patent.domain.TbPamInventorProposalIpr;
import com.xhsj.user.pms.patent.mapper.TbPamInventorProposalIprMapper;
import com.xhsj.user.pms.patent.service.TbPamInventorProposalIprService;
import com.xhsj.user.sms.base.BaseService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.io.Serializable;
import java.util.Collection;
import java.util.List;
import java.util.Map;
import java.util.Objects;

/**
 * <p>
 * 发明人建议IPR 服务实现类
 * </p>
 *
 * @author liuqinghua
 * @since 2020-07-06
 */
@Slf4j
@Service
@Transactional(rollbackFor = Exception.class)
public class TbPamInventorProposalIprServiceImpl extends BaseService<TbPamInventorProposalIprMapper, TbPamInventorProposalIpr> implements TbPamInventorProposalIprService {
    @Autowired
    private TbPamInventorProposalIprMapper dao;

    @Override
    //@CacheEvict(cacheNames="TbPamInventorProposalIpr", allEntries=true)
    public boolean save(TbPamInventorProposalIpr entity) {
        return super.save(entity);
    }

    @Override
    //@Cacheable(key = "#id",sync = true)
    public TbPamInventorProposalIpr getById(Serializable id) {
        return super.getById(id);
    }

    @Override
    //@CacheEvict(cacheNames="TbPamInventorProposalIpr", allEntries=true)
    public boolean removeById(Serializable id) {
        return super.removeById(id);
    }

    //@CacheEvict(cacheNames="SysDict", allEntries=true)
    @Override
    public boolean removeByIds(Collection<? extends Serializable> idList) {
        return super.removeByIds(idList);
    }

    //@Cacheable(key = "#data",sync = true)
    public IPage<TbPamInventorProposalIpr> selectPage(Map<String,Object> data) {
        int currentPage=1;
        if (!Objects.isNull(data.get("page"))) {
            currentPage=(Integer) data.get("page");
        }
        int pageSize=20;
        if (!Objects.isNull(data.get("size"))) {
            pageSize=(Integer) data.get("size");
        }

        TbPamInventorProposalIpr entity = JSON.parseObject(JSON.toJSONString(data), TbPamInventorProposalIpr.class);
        Page<TbPamInventorProposalIpr> page = new Page(currentPage,pageSize);
        QueryWrapper<TbPamInventorProposalIpr> wrapper = new QueryWrapper(entity);
        return super.selectPage(page, wrapper);
    }

    @Override
    public List<TbPamInventorProposalIpr> selectAll() {
        return super.selectAll();
    }


    //根据交底书id删除指派ipr信息
    @Override
    public int deleteByDisclosure(String disclosureId) {
        return dao.deleteByDisclosure(disclosureId);
    }


    // 修改创建者建议的ipr
    public int updateByDisclosureId(String identitylinkForDisclosure, Integer userId, String createBy) {
        return dao.updateByDisclosureId(identitylinkForDisclosure,userId,createBy);
    }
}
